<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title id="divTitle">新建团队</title>
  <link rel="stylesheet" type="text/css" th:href="@{/css/style.css}" />

  <style type="text/css">
    *, body {
      margin: 0px;
      font-family: '微软雅黑';
    }
  </style>
  <script th:src="@{/js/jquery-1.10.2.min.js}"></script>
  <script th:src="@{/js/jquery.form.js}"></script>
  <script th:src="@{/js/generic.js}"></script>
</head>

<body>

<!--<div th:replace="top :: top"></div>-->
<form id="filePost" method="post" enctype="multipart/form-data" onsubmit="return false;">
  <table class="maintable">
    <tr>
      <td class="rightmaintd" valign="top">
        <div style="width:920px;margin:10px auto;"> <a href="/team">&lt;  返回</a> </div>
        <table class="logintable" cellpadding="8" style="margin-top:20px;">

          <tr>
            <td>团队名称</td>
            <td>
              <input type="text" id="TeamName" class="logininput">
            </td>
          </tr>
          <tr>
            <td>医生姓名</td>
            <td><input type="text" id="doctorName" class="logininput"></td>
          </tr>
          <tr>
            <td>电话</td>
            <td><input type="text" id="tel" class="logininput"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input type="button" value="创&nbsp;&nbsp;建" class="denglubtn" id="saveButton" >  </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</form>

</body>
</html>

<script type="text/javascript">


  var saveButton = document.getElementById('saveButton');
  saveButton.addEventListener('click', function() {
    // 获取输入框中的数据
    var teamName = document.getElementById('TeamName').value;
    if(teamName=="") {
      alert("请输入团队名称！");
      return;
    }
    var doctorName = document.getElementById('doctorName').value;
    var tel=document.getElementById('tel').value;
    // 创建要发送的数据对象
    var data = {
      teamName: teamName,
      doctorName: doctorName,
      tel: tel
    };

    // 发送 POST 请求
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/team/', true);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.onreadystatechange = function() {
      console.log(teamName);
      console.log(xhr);
      if (xhr.readyState === 4 && xhr.status === 200) {
        // 请求完成并成功处理后的回调函数
        console.log('数据已成功发送至后端');
        alert("创建成功！");
        window.location.href="/team";
      }
    };
    xhr.send(JSON.stringify(data));
  });


</script>
